/*
	Simple Shadow
	
	Simply adds a 10 pixel graphical shadow to the right and bottom of a div element that has Width and Height specified with CSS. 
	
	Requires jQuery 1.3.2 and the three images - shadow-right.jpg, shadow-corner.jpg and shadow-bottom.jpg. 
	
	@author - Ralph Whitbeck (ralph.whitbeck@gmail.com), http://ralphwhitbeck.com
	
	@version 0.6
	
	@usage $("div").shadow();
*/

(function($){

	if (/1\.(0|1|2|3)\.(0|1)/.test($.fn.jquery) 
			|| /^1.1/.test($.fn.jquery) 
			|| /^1.2/.test($.fn.jquery)) 
	{
		try { console.log('Simple Shadow strongly recommends jQuery v1.3.2 or later! You are using v' + $.fn.jquery); } catch (err) { /*Firebug Console is not enabled.*/ }
	} 

	$.fn.shadow = function() {
		var o = { s: this.selector, c: this.context };

	  	var $this = $(this);
		
		//test to see if element is on the page.  If not ignore.
		if ($this.length > 0)
		{
			var shadowID = ($this.attr("id").length == 0) ? "simple-shadow" : $this.attr("id") + "-shadow";
			var oWidth = $this.outerWidth();
			var oHeight = $this.outerHeight();
			var imagePath = "images/";
		
			//wrap the element in a container div and set it's full width and height with shadows.
			$this.wrap("<div id=\"" + shadowID + "\" style=\"width: " + (oWidth + 10) + "px; height: " + (oHeight + 10) + "px; \"></div>");
				
			//Add the bottom row of the shadow to the element now so that we can work on the top row separately.  Hide the overflow since IE6 with show more then it should.			
			$this.after("<div style=\"width: " + (oWidth + 10) + "px; height: 10px;overflow: hidden;\"><div style=\"width: " + oWidth + "px; height: 10px; background-image: url(" + imagePath + "shadow-bottom.jpg); background-repeat: x-repeat;float: left;\"></div><div style=\"width: 10px; height: 10px;background-image: url(" + imagePath + "shadow-corner.jpg); float: left;\"></div></div>");
			
			//wrap the element in another container that'll be for the top row which includes the element and the right side of the shadow.  Set width and height.
			$this.wrap("<div style=\"width: " + (oWidth + 10) + "px; height: " + oHeight + "px;\"></div>");
				
			//add the div element for the right side shadow.			
			$this.after("<div style=\"width: 10px; height: " + oHeight + "px; float:left; background-image: url(" + imagePath + "shadow-right.jpg); background-repeat: y-repeat;\"></div>");
			
			//float the element left so that it lines up correct with the shadow.
			$this.css("float","left");
		}
	};

})(jQuery);